/**
 * 访问"评论"接口网络模块
 */

import axios from "./axios.config";
import util from "./util";

class ReviewApi {
  async findAllByCakeId(cakeId, limit, offset, orderBy, sort) {
    let result = await axios.get(
      `/reviews?cake_id=${cakeId}&limit=${limit}&offset=${offset}&order_by=${orderBy}&sort=${sort}`
    );
    return util.jsonTransfer(result.data);
  }

  async getCountByCakeId(cakeId) {
    let result = await axios.get(`/reviews/count?cake_id=${cakeId}`);
    return util.jsonTransfer(result.data);
  }

  async add(review) {
    let result = await axios.post("/reviews", review);
    return util.jsonTransfer(result.data);
  }
}

export default ReviewApi;
